﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// 文件名：ClsStockManageDAL.cs
/// 作  者：Kidy
/// 时  间：2006.11.20
/// 说  明：ClsStockManageDAL类用于采购管理信息相关处理
/// </summary>
public class ClsStockManageDAL
{
    /// <summary>
    /// 数据库连接字符串
    /// </summary>
    private static string strSqlConnectionString = ConfigurationManager.AppSettings["SQLCONNECTIONSTRING"];

    /// <summary>
    /// 获取所有主表信息
    /// </summary>
    /// <param name="Type">类型</param>
    /// <param name="sCurUserId">当前用户ID</param>
    /// <returns>返回主表信息数据集</returns>
    public DataSet GetStockOrderMains(int Type,string sCurUserId)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetStockOrderMains", con);
        dat.SelectCommand.CommandType = CommandType.StoredProcedure;

        dat.SelectCommand.Parameters.Add("@type", SqlDbType.NVarChar, 2);
        dat.SelectCommand.Parameters["@type"].Value = Type;
        dat.SelectCommand.Parameters.Add("@u_log_id", SqlDbType.NVarChar, 60);
        dat.SelectCommand.Parameters["@u_log_id"].Value = sCurUserId;

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 获取所有从表信息
    /// <param name="Dm_No">收料或退货单号</param>
    /// <param name="Type">类型</param>
    /// </summary>
    /// <returns>返回从表信息数据集</returns>
    public DataSet GetStockOrderChilds(string Dm_No, string Type)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetStockChilds", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;
        dat.SelectCommand.Parameters.Add("@dm_no", SqlDbType.NVarChar, 30);
        dat.SelectCommand.Parameters["@dm_no"].Value = Dm_No;
        dat.SelectCommand.Parameters.Add("@type", SqlDbType.NVarChar, 2);
        dat.SelectCommand.Parameters["@type"].Value = Type;

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 改变订单的状态
    /// </summary>
    /// <param name="Dm_No">订单单号</param>
    /// <param name="State">操作状态(0确认，1取消确认即终止，2作废即作废，3彻底作废)</param>
    /// <param name="Auditor">操作员</param>
    /// <param name="Type">类型</param>
    /// <returns>操作是否成功</returns>
    public Boolean UpdateStockOrderState(string Dm_No, int State, string Auditor, string Type)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AuditStock", con);//Pro_ChangeStore  Pro_UpdateStockOrderState

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@dm_no", SqlDbType.NVarChar, 30);
        com.Parameters["@dm_no"].Value = Dm_No;
        com.Parameters.Add("@is_audit", SqlDbType.Int, 4);
        com.Parameters["@is_audit"].Value = State;
        com.Parameters.Add("@auditor", SqlDbType.NVarChar, 60);
        com.Parameters["@auditor"].Value = Auditor;
        com.Parameters.Add("@type", SqlDbType.NVarChar, 2);
        com.Parameters["@type"].Value = Type;
        com.Parameters.Add("@code", SqlDbType.NVarChar, 30);
        com.Parameters["@code"].Value = "";

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 改变订单从表的状态
    /// </summary>
    /// <param name="Dm_No">订单单号</param>
    /// <param name="N_No">从表单号</param>
    /// <param name="State">操作状态(0确认，1取消确认即终止，2作废即作废，3彻底作废)</param>
    /// <param name="Type">类型</param>
    /// <returns>操作是否成功</returns>
    public Boolean DeleteStockOrderChildState(string Dm_No, string sId, int State, string Type)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_DeleteStockD", con);
        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@type", SqlDbType.NVarChar, 2);
        com.Parameters["@type"].Value = Type;
        com.Parameters.Add("@dm_no", SqlDbType.NVarChar, 30);
        com.Parameters["@dm_no"].Value = Dm_No;
        com.Parameters.Add("@id", SqlDbType.NVarChar, 30);
        com.Parameters["@id"].Value = sId;
        com.Parameters.Add("@dm_state", SqlDbType.Int, 4);
        com.Parameters["@dm_state"].Value = State;
        

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 新增或修改主表记录
    /// </summary>
    /// <param name="Type">类型</param>
    /// <param name="Dm_No">单号</param>
    /// <param name="Dm_Date">日期</param>
    /// <param name="Dm_Mdate">希望发货日(退货为当前系统时间)</param>
    /// <param name="Ct_Id">供应商ID</param>
    /// <param name="Pm_Id">付款方式ID(退货为空)</param>
    /// <param name="Sm_Id">运输方式ID(退货为空)</param>
    /// <param name="Wh_Id">仓库ID</param>
    /// <param name="Dp_Id">部门ID</param>
    /// <param name="Wk_Id">采购员ID</param>
    /// <param name="Dm_Name">收货人(退货为空)</param>
    /// <param name="Dm_Tel">联系电话(退货为空)</param>
    /// <param name="Dm_Addr">收货地址(退货为空)</param>
    /// <param name="Oper">录入人</param>
    /// <param name="Remark">备注</param>
    /// <param name="OperateType">操作类型(0新增，1修改)</param>
    /// <returns>返回操作是否成功</returns>
    public Boolean AddOrUpdateStockOrder(string Type, string Dm_No, DateTime Dm_Date, DateTime Dm_Mdate, string Ct_Id, 
        string Pm_Id, string Sm_Id, string Wh_Id, string Dp_Id, string Wk_Id, string Dm_Name, string Dm_Tel, 
        string Dm_Addr, string Oper, string Remark, int OperateType)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AddOrUpdateStockOrder", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@type", SqlDbType.NVarChar, 2);
        com.Parameters["@type"].Value = Type;
        com.Parameters.Add("@dm_no", SqlDbType.NVarChar, 30);
        com.Parameters["@dm_no"].Value = Dm_No;
        com.Parameters.Add("@dm_date", SqlDbType.DateTime, 8);
        com.Parameters["@dm_date"].Value = Dm_Date;
        com.Parameters.Add("@dm_mdate", SqlDbType.DateTime, 8);
        com.Parameters["@dm_mdate"].Value = Dm_Mdate;
        com.Parameters.Add("@ct_id", SqlDbType.NVarChar, 20);
        com.Parameters["@ct_id"].Value = Ct_Id;
        com.Parameters.Add("@pm_id", SqlDbType.NVarChar, 20);
        com.Parameters["@pm_id"].Value = Pm_Id;
        com.Parameters.Add("@sm_id", SqlDbType.NVarChar, 20);
        com.Parameters["@sm_id"].Value = Sm_Id;
        com.Parameters.Add("@wh_id", SqlDbType.NVarChar, 20);
        com.Parameters["@wh_id"].Value = Wh_Id;
        com.Parameters.Add("@dp_id", SqlDbType.NVarChar, 20);
        com.Parameters["@dp_id"].Value = Dp_Id;
        com.Parameters.Add("@wk_id", SqlDbType.NVarChar, 20);
        com.Parameters["@wk_id"].Value = Wk_Id;
        com.Parameters.Add("@dm_name", SqlDbType.NVarChar, 60);
        com.Parameters["@dm_name"].Value = Dm_Name;
        com.Parameters.Add("@dm_tel", SqlDbType.NVarChar, 60);
        com.Parameters["@dm_tel"].Value = Dm_Tel;
        com.Parameters.Add("@dm_addr", SqlDbType.NVarChar, 255);
        com.Parameters["@dm_addr"].Value = Dm_Addr;
        com.Parameters.Add("@oper", SqlDbType.NVarChar, 60);
        com.Parameters["@oper"].Value = Oper;
        com.Parameters.Add("@remark", SqlDbType.NVarChar, 255);
        com.Parameters["@remark"].Value = Remark;
        com.Parameters.Add("@operate_type", SqlDbType.Int, 4);
        com.Parameters["@operate_type"].Value = OperateType;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 新增或修改采购入库/退货从表记录
    /// </summary>
    /// <param name="Type">类型</param>
    /// <param name="Dm_No">采购订单号</param>
    /// <param name="Im_No">商品编号</param>
    /// <param name="Qty">数量</param>
    /// <param name="Remark">备注</param>
    /// <param name="OperateType">操作类型(0新增，1修改)</param>
    /// <returns>返回操作是否成功</returns>
    public Boolean AddOrUpdateStockOrderChild(int id,string Type, string Dm_No,string Im_No, decimal Qty, decimal dPrice,
        decimal dSellPrice,String sBatchNo, string Remark, int OperateType)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AddOrUpdateStockOrderChild", con);
        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@id", SqlDbType.Int);
        com.Parameters["@id"].Value = id;
        com.Parameters.Add("@type", SqlDbType.NVarChar, 2);
        com.Parameters["@type"].Value = Type;
        com.Parameters.Add("@dm_no", SqlDbType.NVarChar, 30);
        com.Parameters["@dm_no"].Value = Dm_No;
        com.Parameters.Add("@im_no", SqlDbType.NVarChar, 30);
        com.Parameters["@im_no"].Value = Im_No;
        com.Parameters.Add("@qty", SqlDbType.Decimal, 17);
        com.Parameters["@qty"].Value = Qty;
        com.Parameters.Add("@price", SqlDbType.Decimal, 28);
        com.Parameters["@price"].Value = dPrice;
        com.Parameters.Add("@sellPrice", SqlDbType.Decimal, 28);
        com.Parameters["@sellPrice"].Value = dSellPrice;
        com.Parameters.Add("@lot_no", SqlDbType.NVarChar, 30);
        com.Parameters["@lot_no"].Value = sBatchNo;
        com.Parameters.Add("@remark", SqlDbType.NVarChar, 255);
        com.Parameters["@remark"].Value = Remark;
        com.Parameters.Add("@operate_type", SqlDbType.Int, 4);
        com.Parameters["@operate_type"].Value = OperateType;

        try
        {
            con.Open();
            com.ExecuteNonQuery();
            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }



    public DataSet GetStockMains(string aa, string bb, string cc)
    {
        return null;
    }
    public DataSet GetStockChilds(string Dm_No, string Type)
    {
        return null;
    }

    /// <summary>
    /// 搜索采购订单信息 ADD BY KIDY ON 20061204
    /// </summary>
    /// <param name="Key">搜索关键字</param>
    /// <param name="SearchType">搜索方式(0精确，1模糊)</param>
    /// <param name="Type">类型(0客户，1供应商)</param>
    /// <returns>返回数据集</returns>
    public DataSet SearchStockOrders(string Key, int SearchType, string sType)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_SearchStockOrderDS", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;
        dat.SelectCommand.Parameters.Add("@key", Key);
        dat.SelectCommand.Parameters.Add("@searchtype", SqlDbType.Int, 4);
        dat.SelectCommand.Parameters["@searchtype"].Value = SearchType;
        dat.SelectCommand.Parameters.Add("@type", SqlDbType.NVarChar, 2);
        dat.SelectCommand.Parameters["@type"].Value = sType;

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 改变订单的状态
    /// </summary>
    /// <param name="Dm_No">订单单号</param>
    /// <param name="State">操作状态(0确认，1取消确认即终止，2作废即作废，3彻底作废)</param>
    /// <param name="Auditor">操作员</param>
    /// <param name="Type">类型</param>
    /// <returns>操作是否成功</returns>
    public Boolean DeleteStockOrderState(string Dm_No, int State, string Type)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_deleteStockM", con);//Pro_ChangeStore

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@dm_no", SqlDbType.NVarChar, 30);
        com.Parameters["@dm_no"].Value = Dm_No;
        com.Parameters.Add("@dm_state", SqlDbType.Int, 4);
        com.Parameters["@dm_state"].Value = State;
        com.Parameters.Add("@type", SqlDbType.NVarChar, 2);
        com.Parameters["@type"].Value = Type;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }


    /// <summary>
    /// 检查采购入库是否可以取消确认：依据（没有出库记录）
    /// <returns>CREATE BY KIDY ON 20061208</returns>
    /// </summary>
    public String CheckWhetherAudtitStockIn(string sDm_No, string sType)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_CheckWhetherAuditByStockIn", con);        
        com.CommandType = CommandType.StoredProcedure;
        SqlParameter ParOutPut = new SqlParameter();

        com.Parameters.Add("@dm_no", SqlDbType.NVarChar, 30);
        com.Parameters["@dm_no"].Value = sDm_No;
        com.Parameters.Add("@type", SqlDbType.NVarChar, 2);
        com.Parameters["@type"].Value = sType;
        ParOutPut = com.Parameters.Add("@relot_no", SqlDbType.NVarChar, 30);
        ParOutPut.Direction = ParameterDirection.Output;
        ParOutPut = com.Parameters.Add("@returnState", SqlDbType.Bit, 1);
        ParOutPut.Direction = ParameterDirection.Output;

        try
        { 
            con.Open();
            com.ExecuteNonQuery();
            Boolean bTorf = (Boolean)com.Parameters["@returnState"].Value;
            string strReLot_no = "";
            if (bTorf)           
            {
                return strReLot_no;
            }
            else            
            {
                strReLot_no = (string)com.Parameters["@relot_no"].Value.ToString();
            }
            return strReLot_no;                     
        }
        catch
        {
            return "";
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 检查采购退货是否可以确认：依据（没有入库记录）
    /// <returns>CREATE BY KIDY ON 20061208</returns>
    /// </summary>
    public String CheckWhetherAudtitStockOut(string sDm_No, string sType)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_CheckWhetherAuditByStockOut", con);
        com.CommandType = CommandType.StoredProcedure;
        SqlParameter ParOutPut = new SqlParameter();

        com.Parameters.Add("@dm_no", SqlDbType.NVarChar, 30);
        com.Parameters["@dm_no"].Value = sDm_No;
        com.Parameters.Add("@type", SqlDbType.NVarChar, 2);
        com.Parameters["@type"].Value = sType;
        ParOutPut = com.Parameters.Add("@relot_no", SqlDbType.NVarChar, 30);
        ParOutPut.Direction = ParameterDirection.Output;
        ParOutPut = com.Parameters.Add("@returnState", SqlDbType.NVarChar, 2);
        ParOutPut.Direction = ParameterDirection.Output;

        try
        {
            con.Open();
            com.ExecuteNonQuery();
            string strTorf = com.Parameters["@returnState"].Value.ToString();
            string strReLot_no = (string)com.Parameters["@relot_no"].Value.ToString();
            if (strTorf == "1")
            {
                strReLot_no = "";
            }
            else if (strTorf == "0" && strReLot_no.Length == 0)
            {
                strReLot_no = "strNull";
            }
            else if (strTorf == "2")
            {
                return "2";
            }
            return strReLot_no;
        }
        catch
        {
            return "";
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// (公用)判断改变库存后是否可以取消确认
    /// </summary>
    /// <param name="@type">类型</param>
    /// <param name="@BodNo">单据号</param>
    /// <param name="@tabM">主表一</param>
    /// <param name="@tab1M">主表二</param>
    /// <param name="@Bodcolname">关联的单据列名</param>
    /// <param name="@Typecolname">类型列名</param>
    /// <returns>返回是否可以取消确认</returns>
    public bool pubWhetherNonAudit(string sType, string sBodNo, string sTab, string sTab1, string sBodcolname, string sTypecolname)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_BodTrueAudit", con);
        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@type", SqlDbType.NVarChar, 30);
        com.Parameters["@type"].Value = sType;
        com.Parameters.Add("@BodNo", SqlDbType.NVarChar, 30);
        com.Parameters["@BodNo"].Value = sBodNo;
        com.Parameters.Add("@tabM", SqlDbType.NVarChar, 30);
        com.Parameters["@tabM"].Value = sTab;
        com.Parameters.Add("@tab1M", SqlDbType.NVarChar, 30);
        com.Parameters["@tab1M"].Value = sTab1;
        com.Parameters.Add("@Bodcolname", SqlDbType.NVarChar, 30);
        com.Parameters["@Bodcolname"].Value = sBodcolname;
        com.Parameters.Add("@Typecolname", SqlDbType.NVarChar, 30);
        com.Parameters["@Typecolname"].Value = sTypecolname;

        try
        {
            con.Open();
            Boolean bAuditState = (Boolean)com.ExecuteScalar();
            return bAuditState;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 根据查询状态获取采购入库/退货所有主表信息
    /// </summary>CREATE BY KIDY ON 20061226
    /// <param name="Type">类型</param>
    /// <returns>返回主表信息数据集</returns>
    public DataSet GetOrderInformationByStatu(string sCurUserId,string sTable,int iType,int iQueryType)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetOrderByStatu", con);//Pro_GetValidateOrderByStatu
        dat.SelectCommand.CommandType = CommandType.StoredProcedure;

        dat.SelectCommand.Parameters.Add("@u_log_id", SqlDbType.VarChar, 30);
        dat.SelectCommand.Parameters["@u_log_id"].Value = sCurUserId;
        dat.SelectCommand.Parameters.Add("@table", SqlDbType.VarChar, 30);
        dat.SelectCommand.Parameters["@table"].Value = sTable;
        dat.SelectCommand.Parameters.Add("@type", SqlDbType.Int, 2);
        dat.SelectCommand.Parameters["@type"].Value = iType;
        dat.SelectCommand.Parameters.Add("@queryType", SqlDbType.Int, 2);
        dat.SelectCommand.Parameters["@queryType"].Value = iQueryType;

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
        return dst;
    }

    /// <summary>
    /// 根据查询状态获取入库/退货确认所有主表信息
    /// </summary>CREATE BY KIDY ON 20070114
    /// <param name="Type">类型</param>
    /// <returns>返回主表信息数据集</returns>
    public DataSet GetStockValidateByStatu(string sCurUserId, string sTable, int iType, int iQueryType)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetValidateOrderByStatu", con);
        dat.SelectCommand.CommandType = CommandType.StoredProcedure;

        dat.SelectCommand.Parameters.Add("@u_log_id", SqlDbType.VarChar, 30);
        dat.SelectCommand.Parameters["@u_log_id"].Value = sCurUserId;
        dat.SelectCommand.Parameters.Add("@table", SqlDbType.VarChar, 30);
        dat.SelectCommand.Parameters["@table"].Value = sTable;
        dat.SelectCommand.Parameters.Add("@type", SqlDbType.Int, 2);
        dat.SelectCommand.Parameters["@type"].Value = iType;
        dat.SelectCommand.Parameters.Add("@queryType", SqlDbType.Int, 2);
        dat.SelectCommand.Parameters["@queryType"].Value = iQueryType;

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 终止单据(CREATE BY KIDY ON 20070102)
    /// </summary>
    /// <param name="sType">类型</param>
    /// <param name="sTabName">表名</param>
    /// <param name="sColname">单据列名</param>
    /// <param name="sBOD_no">单据号</param>
    /// <param name="sTypeColname">类型列名</param>
    /// <returns></returns>
    public Boolean EndBOD_no(string sType, string sTabName,string sColname, string sBOD_no,string sTypeColname)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_EndBOD", con);
        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@type", SqlDbType.NVarChar, 2);
        com.Parameters["@type"].Value = sType;
        com.Parameters.Add("@tabname", SqlDbType.NVarChar, 30);
        com.Parameters["@tabname"].Value = sTabName;
        com.Parameters.Add("@colname", SqlDbType.NVarChar, 30);
        com.Parameters["@colname"].Value = sColname;
        com.Parameters.Add("@no", SqlDbType.NVarChar, 30);
        com.Parameters["@no"].Value = sBOD_no;
        com.Parameters.Add("@typeColname", SqlDbType.NVarChar, 30);
        com.Parameters["@typeColname"].Value = sTypeColname;

        try
        {
            con.Open();

            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }
}
